var add,edit,setVal,reset;
require(['select2', 'date','layout','validator'], function() {
	var $formData = $('#formData');
	$formData.initForm();
	
	add = function(fn) {
		addOrUpdate("/faultType/addFaultType.htm",fn);
	};
	
	edit = function(fn) {
		addOrUpdate("/faultType/editFaultType.htm",fn);
	};
	
	setVal = function (rowidstr){
		$.ajaxExt({
			url :"/faultType/getFaultTypeById.htm",
			data : {'rowidstr' : rowidstr}
		}).done(function(data){
			$formData.setValues(data[0]);
		});
	};
	
	reset = function (corpId){
		$formData.reset($formData);
		$("#corpId").val(corpId);
	};
	
	function addOrUpdate(url,callBack){
		var result = $.validator($formData);
    	if(result){
    		$.ajaxExt({
    			url : url,
    			data : $formData.getValues()
    		}).done(function(){
    			callBack();
    		});
    	}
	}
});